﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace CloudMusic.Converters
{
    public class PictureConvert : IValueConverter
    {
        /// <summary>
        /// 转换图片
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            BitmapImage musicPicture = null;
            musicPicture = new BitmapImage(new Uri(value.ToString()));
            byte[] image = (byte[])value;
            if (image != null)
            {
                MemoryStream ms = new MemoryStream(image);
                musicPicture = new BitmapImage();
                musicPicture.BeginInit();
                musicPicture.StreamSource = ms;
                musicPicture.EndInit();
            }
            return musicPicture;

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
